{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# Pydantic模块入门示例"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "# Pserson\n",
    "\n",
    "from pydantic import BaseModel\n",
    "\n",
    "class Person(BaseModel):\n",
    "    name: str\n",
    "    age: int\n",
    "    email: str"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "yzpang\n",
      "Name: yzpang\n",
      "Age: 35\n",
      "Email: yzpang@example.com\n"
     ]
    }
   ],
   "source": [
    "# app\n",
    "import json\n",
    "# Json数据示例\n",
    "json_data = '''\n",
    "{\n",
    "    \"name\": \"yzpang\",\n",
    "    \"age\": 35,\n",
    "    \"email\": \"yzpang@example.com\"\n",
    "}\n",
    "'''\n",
    "\n",
    "# 将json解析为Person对象\n",
    "person_data = json.loads(json_data)\n",
    "person = Person(**person_data)\n",
    "\n",
    "# 访问已验证的数据\n",
    "print(f'Name: {person.name}')\n",
    "print(f'Age: {person.age}')\n",
    "print(f'Email: {person.email}')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}